//
//  CollectController.swift
//  MSwift
//
//  Created by 马龙波 on 2017/11/3.
//  Copyright © 2017年 马龙波. All rights reserved.
//

import UIKit

class CollectController: BaseController {

    
    let cellID = "cellString"
    
    
    var collectionView = UICollectionView()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        createUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

   

}

extension CollectController {
    func createUI() {
        
        let layout = UICollectionViewLayout()
        
        collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: kScreenW, height: kScreenH-kNavgationH), collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        view.addSubview(collectionView)
        
//        collectionView .register(class_getName(UITableViewCell), forCellWithReuseIdentifier: cellID)
    }
}

extension CollectController : UICollectionViewDelegate , UICollectionViewDataSource ,UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }
    //每个item大小
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: kScreenW/2-10, height: kScreenW*3/5)
    }
    //组内item间距(上下？)
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 15
    }
    //组内item间距(左右？)
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 10
    }
    //每个组item的边距
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsetsMake(10, 0, 10, 0)
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        var cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath)
        if cell = nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: cellID)
        }
        return cell
    }
}

